package com.atguigu.gulimall.member.config;

import com.alibaba.nacos.common.utils.StringUtils;
import feign.RequestInterceptor;
import feign.RequestTemplate;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import java.math.BigDecimal;


/**
 * @author ly
 */
@Configuration
public class GuliFeignConfig {
    /**
     * 在容器中添加拦截器
     *
     * @return
     */
    @Bean("requestInterceptor")
    public RequestInterceptor requestInterceptor() {
        return new RequestInterceptor() {
            @Override
            public void apply(RequestTemplate requestTemplate) {
                //RequestContextHolder获取刚进来携带的请求头信息
                ServletRequestAttributes attributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
                if (attributes != null) {
                    System.out.println("RequestInterceptor线程....." + Thread.currentThread().getId());
                    HttpServletRequest request = attributes.getRequest(); //老请求
                    //获取老请求头中的cookie
                    String cookie = request.getHeader("Cookie");
                    //给新请求同步老请求数据cookie
                    requestTemplate.header("Cookie", cookie);
                }
            }
        };
    }
    public static void main(String[] args) {
        System.out.println(Integer.MAX_VALUE);

    }
}
